package com.baiyi.homeui.hshomeui.util;

import android.content.Context;
import android.content.SharedPreferences;


public class SpUtils {


    private final String HSSHARE = "hs_home_share";
    private static SpUtils instance;

    public static final String KEY_BRIGHTNESS = "key_brightness";
    private SharedPreferences sharedPreferences;
    
    public static SpUtils getInstance(){
        if (instance==null){
            instance = new SpUtils();
        }
        return instance;
    }

    public String getStringValue(Context context, String key){

        sharedPreferences= context.getSharedPreferences(HSSHARE,
                Context.MODE_PRIVATE);
        return sharedPreferences.getString(key,"");
    }

    public void saveValue(Context context,String key,String value){
        sharedPreferences= context.getSharedPreferences(HSSHARE,
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key,value);
        editor.apply();
    }

    public int getIntValue(Context context, String key){

        sharedPreferences= context.getSharedPreferences(HSSHARE,
                Context.MODE_PRIVATE);
        return sharedPreferences.getInt(key,0);
    }

    public int getBrightnessValue(Context context){

        sharedPreferences= context.getSharedPreferences(HSSHARE,
                Context.MODE_PRIVATE);
        return sharedPreferences.getInt(KEY_BRIGHTNESS,204);
    }

    public void saveIntValue(Context context,String key,int value){
        sharedPreferences= context.getSharedPreferences(HSSHARE,
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt(key,value);
        editor.apply();
    }

}
